package devmento.gae.resources;

import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import devmento.gae.dao.EmployeeDao;
import devmento.gae.model.Employee;

@Path("/employees")
@Component
public class EmployeeResource {
        final Logger logger = LoggerFactory.getLogger(EmployeeResource.class);
        
        @Autowired
        private EmployeeDao employeeDao;
        
        @GET
        @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
        public Employee[] getEmployeeAll(){
        	logger.info("start employee all");
        	return employeeDao.findAll();
        }
        
        @GET
        @Path("/{id}")
        @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
        public Employee getEmployee(@PathParam("id")String id){
        	return employeeDao.find(id);
        }
        
        @DELETE
        @Path("/{id}")
        public void deleteEmployee(@PathParam("id")String id){
            employeeDao.delete(id);
        }
        
        @POST
        @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
        public void createEmployee(Employee emp){
        	employeeDao.save(emp);
        }
        
        @PUT
        @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
        public void updateEmployee(Employee emp){
        	employeeDao.save(emp);
        }
}

